<template>
<el-main>
    <div class="chat-list">
        <div class="chat-item" v-for="(item,index) in messageList" :key="index">
            <div>{{item.from_user_id}}</div>
            <div>{{item.create_at}}</div>
            <div>{{item.content}}</div>
        </div>
    </div>

    <el-row>
        <el-col :span="12">
            <el-form ref="form" :model="form" label-position="top">
                <el-form-item label="消息内容">
                    <el-input type="textarea" v-model="form.content" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">发送</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <el-col :span="12"></el-col>
    </el-row>

</el-main>
</template>

<script>
import {
    mapGetters
} from "vuex";

let form = {
    from_user_id: "",
    target_user_id: "",
    content: "",
    type: "broadcast"
};

export default {
    computed: {
        ...mapGetters(["messageList"]),
    },
    data() {
        return {
            formDrawer: {
                title: "内部沟通",
                visible: false
            },
            form: Object.assign({}, form)
        }
    },
    methods: {
        onSubmit() {
            this.$socket.send(this.form)
        }
    }
}
</script>

<style lang="less" scoped>
.chat-list {
    height: 60vh;
    width: 50%;
    overflow: auto;
    border: 1px solid #ccc;
    margin-bottom: 1rem;

    .chat-item {
        flex: 0 50%;
        padding: 10px;
        border-bottom: 1px solid #ccc;
    }

    .chat-item:nth-child(even) {
        text-align: right;
        background-color: #f5f5f5;
    }
}
</style>
